package com.zyz.K_集合.collection接口;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author: vick
 * @Date: 2025/3/27
 * @Description:
 * @version: 1.0
 */
public class TestCollectionRemove {
    public static void main(String[] args) {
        Collection collection = new ArrayList();
        collection.add(111);
        collection.add(222);
        collection.add(111);
        collection.add("vick");
        collection.add(new String("aaaa"));
        collection.add(111);
        System.out.println(collection);
        System.out.println("c1集合元素的个数：" + collection.size());

        collection.remove(111);
        System.out.println(collection);
        collection.remove("aaaa");
        System.out.println(collection);

        System.out.println("====");


        Collection collection2 = new ArrayList();
        collection2.add(111);
        collection2.add(222);
        collection2.add(333);
        collection2.add("vick");

        Collection collection3 = new ArrayList();
        collection3.add(222);
        collection3.add(333);

        //从当前集合中删除所有与c集合中相同的元素
        collection2.removeAll(collection3);
        System.out.println(collection2);

        //清空集合
        collection2.clear();
        System.out.println(collection2);

        System.out.println("======");
        Collection collection4 = new ArrayList();
        collection4.add(111);
        collection4.add(222);
        collection4.add(333);
        collection4.add("vick");


        Collection collection5 = new ArrayList();
        collection5.add(222);
        collection5.add(333);

        //交集
        collection4.retainAll(collection5);
        System.out.println(collection4);
    }
}
